<template>
	<view class="ys">
		<view class="list" v-for="(item,index) in list" :key="index">
			<view class="item">
				<view class="title">
					<view class="left">
						<text class="id">{{item.order_no}}</text><text v-if="item.is_penalty==0"> (免罚)</text>
					</view>
					<text class="tips">{{item.status.text}}</text>
				</view>
				<view class="left">
					<view class="imgbox">
						<image :src="item.staff.avatar_path" mode=""></image>
					</view>
					<view class="info">
						<view class="name">
							{{item.staff.name}}
						</view>
						<view class="type">
							{{item.type.text}} ({{item.money}}元)
						</view>
						<view class="time">
							{{item.create_time}}
						</view>
					</view>
				</view>
				<view class="btns" v-if="item.show_cancel">
					<button @click="cancelPenalty(item)">免罚</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		penalty,
		cancelPenalty
	} from "@/api/user.js"
	export default {
		data() {
			return {
				list: [],
				page: 1,
				last_page: 1
			}
		},
		onLoad() {
			this.penalty()
		},
		onReachBottom() {
			if (this.page < this.last_page) {
				this.page++
				this.penalty()
			}
		},
		methods: {
			cancelPenalty(item) {
				var that = this
				uni.showModal({
					title: '提示',
					content: '确认取消此罚单吗?',
					success(data) {
						if (data.confirm) {
							cancelPenalty({
								id: item.id
							}).then(res => {
								uni.$showMsg(res.msg)
								if (res.code == 0) {
									item.show_cancel = false
									item.is_penalty = 0
								}
							})
						}
					}
				})
			},
			penalty() {
				penalty({
					page: this.page
				}).then(res => {
					if (res.code == 0) {
						this.list = this.list.concat(res.data.data)
						this.last_page = res.data.last_page
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.list {
		padding: 10px;
		box-sizing: border-box;

		.item {
			background: #fff;
			border-radius: 7px;
			padding: 10px;
			box-sizing: border-box;

			.title {
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-size: 14px;
				padding-bottom: 10px;
				border-bottom: 1px solid #eee;

				.id {
					font-weight: bold;
					margin-right: 5px;
				}

				.tips {
					font-size: 12px;
				}
			}

			.left {
				display: flex;
				align-items: center;

				.imgbox {
					width: 60px;
					height: 60px;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.info {
					width: calc(100% - 60px);
					padding-left: 25px;
					box-sizing: border-box;
				}
			}

			.name {
				margin-top: 10px;
			}

			.type {
				padding: 10px 0;
			}

			.time {
				padding-bottom: 10px;
				color: #777;
				font-size: 12px;
			}

			.btns {
				display: flex;
				justify-content: flex-end;
				border-top: 1px solid #eee;
				padding-top: 10px;

				button {
					font-size: 12px;
					margin: 0;
					padding: 0;
					width: 60px;
					background: $uni-bg-color;
					color: #fff;
				}
			}
		}
	}
</style>